package com.it.common;

/**
 * 业务异常错误码定义类
 *
 * @author smartlv
 */
public enum ErrorCode {

    SUCCESS(ErrorCategory.RET_SUCCESS, 0, ""),

    FAIL(ErrorCategory.RET_COMMON, 1, "请求处理错误"),

    LOGIN_ERROR(ErrorCategory.RET_COMMON, 40000, "用户名或者密码错误"),

    NOT_LOGIN(ErrorCategory.RET_COMMON, 40001, "请先登陆！"),

    NOT_PERMIT(ErrorCategory.RET_COMMON, 40002, "权限不足"),


    ;

    /**
     * category
     */
    private final ErrorCategory category;

    /**
     * code
     */
    private final int code;

    /**
     * message
     */
    private String message;

    /**
     * ErrorCode
     *
     * @param code
     * @param message
     */
    ErrorCode(int code, String message) {
        this(ErrorCategory.RET_API, code, message);
    }

    /**
     * ErrorCode
     *
     * @param category
     * @param code
     * @param message
     */
    ErrorCode(ErrorCategory category, int code, String message) {
        this.category = category;
        this.code = code;
        this.message = message;
    }

    /**
     * getCategory
     *
     * @return
     */
    public ErrorCategory getCategory() {
        return category;
    }

    /**
     * getCode
     *
     * @return
     */
    public int getCode() {
        return code;
    }

    /**
     * getMessage
     *
     * @return
     */
    public String getMessage() {
        return message;
    }

    public ErrorCode setMessage(String message) {
        this.message = message;
        return this;
    }

    public static ErrorCode errorCodeValueOf(Integer code) {
        if (code == null) {
            return null;
        }

        for (ErrorCode errorCodeEnum : ErrorCode.values()) {
            if (code == errorCodeEnum.getCode()) {
                return errorCodeEnum;
            }
        }
        return null;
    }
}
